/*****************************************************************************
* Keppe Messenger (KMP) Keppe Project-Team User Messaging System
* Copyright (C) 2013-2014 Keppe Project-Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/

#include "frmMenu.h"
#include "frmLogin.h"
#include "frmProfile.h"
#include "frmChangePassword.h"
#include "ui_frmMenu.h"
#include <QDesktopWidget>
#include <QMessageBox>
QString accountMM;
QString nickMM;
QString messageMM;
QString contactsMM;
QObject *formMM;

frmMenu::frmMenu(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::frmMenu)
{
    ui->setupUi(this);
}

void frmMenu::setNick(QString nick)
{
    nickMM = nick;
}

void frmMenu::setMessage(QString message)
{
    messageMM = message;
}

void frmMenu::setData(QString account, QString nick, QString message, QString contacts)
{
    accountMM = account;
    nickMM = nick;
    messageMM = message;
    contactsMM = contacts;
}

void frmMenu::setForm(frmLogin* login)
{
    formMM = login;
}

frmMenu::~frmMenu()
{
    delete ui;
}

void frmMenu::on_cmdOnline_clicked()
{
    frmLogin* login = (frmLogin*)formMM;
    login->setStateOnline();
}

void frmMenu::on_cmdAway_clicked()
{
    frmLogin* login = (frmLogin*)formMM;
    login->setStateAway();
}

void frmMenu::on_cmdBusy_clicked()
{
    frmLogin* login = (frmLogin*)formMM;
    login->setStateBusy();
}

void frmMenu::on_cmdNotjust_clicked()
{
    frmLogin* login = (frmLogin*)formMM;
    login->setStateNotjust();
}

void frmMenu::on_cmdShowoffline_clicked()
{
    frmLogin* login = (frmLogin*)formMM;
    login->setStateShowoffline();
}

void frmMenu::on_cmdLogoutTemp_clicked()
{
    int ret = QMessageBox::question(this,"Keppe Messenger","Logout (Exit, Temp)?",QMessageBox::Yes,QMessageBox::No);
    if (ret == QMessageBox::Yes)
    {
        frmLogin* login = (frmLogin*)formMM;
        login->logoutUser();
        login->close();
        this->close();
    }
}

void frmMenu::on_cmdLogoutPerm_clicked()
{
    int ret = QMessageBox::question(this,"Keppe Messenger","Logout (Perm)?",QMessageBox::Yes,QMessageBox::No);
    if (ret == QMessageBox::Yes)
    {
        frmLogin* login = (frmLogin*)formMM;
        login->logoutUserWithRemoveAutologin();
        this->close();
    }
}

void frmMenu::on_cmdEditProfile_clicked()
{
    frmProfile* pe = new frmProfile();
    pe->setMenu(this);
    pe->setForm((frmLogin*)formMM);
    pe->setData(accountMM,nickMM,messageMM,contactsMM);
    pe->adjustSize();
    pe->showMaximized();
}

void frmMenu::on_cmdChangePassword_clicked()
{
    frmChangePassword *cp = new frmChangePassword();
    cp->setForm((frmLogin*)formMM);
    cp->adjustSize();
    cp->showMaximized();
}

void frmMenu::on_cmdOK_clicked()
{
    this->close();
}

void frmMenu::on_cmdAddcontact_clicked()
{
    frmLogin *login = (frmLogin*)formMM;
    login->addContactOverMenu(this);
}
